package com.fenshi.presenter.imp;

import android.app.Activity;
import android.content.Context;

import com.amap.api.maps2d.model.LatLng;
import com.android.volley.VolleyError;
import com.fenshi.interactor.ParkInteractor;
import com.fenshi.interactor.imp.ParkInteractorImp;
import com.fenshi.presenter.listener.RequestListener;
import com.fenshi.until.CookicUntil;
import com.fenshi.view.LocationView;

/**
 * Created by lilongfei on 15/12/13.
 */
public class ParkLocationPresenterImp implements RequestListener {

    LocationView view;
    ParkInteractor interactor;
    Context context;

    public ParkLocationPresenterImp(Context context){
        this.context = context;
        this.view = (LocationView) context;
        this.interactor = new ParkInteractorImp(context,this);
    }

    public void saveLocation(){
        LatLng latLng = view.getLocation();
        String userSession = CookicUntil.getUser().getUserId();
        String parkId = CookicUntil.getUser().getParkId();

        if (latLng==null){
            view.showInfo("定位不成功,请稍后重试");
            return;
        }
        view.showSubmit();
        interactor.updateParkLocation(userSession,latLng.latitude,latLng.longitude,parkId);

    }

    @Override
    public void Success(String tag, Object result) {
        view.showInfo((String) result);
        ((Activity) context).finish();
    }

    @Override
    public void Error(String tag, String error) {
        view.dismissSubmit();
        view.showInfo(error);
    }

    @Override
    public void Exception(String tag, VolleyError error) {
        view.dismissSubmit();
        view.showInfo("服务器异常，请稍后重试");
    }
}
